package com.dingding.service.account.core.tailwind.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.IBaseDaoX;
import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.beans.PassangerDepositAccount;
import com.dingding.facade.account.common.dto.tailwind.ResGetDepositAccount;
import com.dingding.facade.account.common.dto.tailwind.ResUAStatus;
import com.dingding.service.account.core.tailwind.dao.IDepositAccountDao;
import com.dingding.service.account.core.tailwind.sql.DepositAccountSQL;

/**
 * 
 * @ClassName: DepositAccountDaoImpl 
 * @Description: 用户提现账户DAO实现类
 * @author YHQ
 * @date 2016年12月21日 下午3:54:03
 * @since V2.6.3
 * 
 */
@Component("depositAccountDao")
public class DepositAccountDaoImpl implements IDepositAccountDao{

	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource(name = "SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	@Resource(name = "baseDaoX")
	private IBaseDaoX baseDaoX;
	
	/**
	 * 
	 * @Title: getUserAuthenticationStatus 
	 * @Description: 获取顺风车用户提现认证状态
	 * @param userId 用户Id
	 * @author YHQ 
	 * @since V2.5.8
	 * @return ResUAStatus 返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public ResUAStatus getUserAuthenticationStatus(String userId) {
		
		try {
			return sqlBaseDao.sqlToCustomBeanUnique(ResUAStatus.class, DepositAccountSQL.GET_USER_ACCOUNT_AUTHENTICATION_STATUS, userId);
		} catch (Exception e) {
			log.error("获取专车用户提现认证状态时出现异常  类：" + this.getClass() + " getSpecialUserAuthenticationStatus()",e);
		}
		
		return null;
	}
	
	/**
	 * 
	 * @Title: addDepositAccount 
	 * @Description: 根据用户id添加用户提现账户
	 * @param depositAccount 用户提现账户信息
	 * @author YHQ 
	 * @since V2.5.8
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean addDepositAccount(PassangerDepositAccount depositAccount) {
		
		try {
			baseDaoX.save(depositAccount);
			return true;
		} catch (Exception e) {
			log.error("根据用户id添加用户提现账户时出现异常   类：" + this.getClass() + " addDepositAccount()", e);
		}
		
		return false;
	}

	/**
	 * 
	 * @Title: deleteDepositAccount 
	 * @Description: 根据用户id删除提现账户
	 * @param depositAccountId 提现账户主键
	 * @param userId 用户Id
	 * @author YHQ 
	 * @since V2.5.8 
	 * @return boolean    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean deleteDepositAccount(Integer depositAccountId,String userId) {
		
		try {
			return sqlBaseDao.updateSqLRow(DepositAccountSQL.DELETE_DEPOSIT_ACCOUNT,depositAccountId, userId);
		} catch (Exception e) {
			log.error("根据用户id删除提现账户时出现异常   类：" + this.getClass() + " deleteDepositAccount()", e);
		}
		
		return false;
	}

	/**
	 * 
	 * @Title: getDepositAccountList 
	 * @Description: 根据用户id获取提现账户列表
	 * @param userId 用户Id
	 * @author YHQ 
	 * @since V2.5.8
	 * @return List<ResGetDepositAccount>    返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public List<ResGetDepositAccount> getDepositAccountList(String userId) {
		
		try {
			return sqlBaseDao.listSqlToCustomBean(ResGetDepositAccount.class, DepositAccountSQL.GET_DEPOSIT_ACCOUNT_LIST, userId);
		} catch (Exception e) {
			log.error("根据用户id获取提现账户列表时出现异常   类：" + this.getClass() + " getDepositAccountList()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: getPassangerDepositAccount 
	 * @Description: 根据用户Id获取全部用户提现账户列表(启用和禁用)
	 * @param userId 用户Id
	 * @author YHQ 
	 * @since V2.6.3
	 * @return List<PassangerDepositAccount>    返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public List<PassangerDepositAccount> getPassangerDepositAccount(String userId) {
		
		try {
			return sqlBaseDao.listSqlToCustomBean(PassangerDepositAccount.class, DepositAccountSQL.GET_ALL_DEPOSIT_ACCOUNT_LIST, userId);
		} catch (Exception e) {
			log.error("根据用户id获取提现账户列表(启用和禁用)时出现异常   类：" + this.getClass() + " getPassangerDepositAccount()", e);
		}
		
		return null;
	}

}
